/**
 * @description:登录过程
 * @version 1.2
 * @history:
 * @author:Aaron
 */

Ext_.namespace('lngtms');

Ext_.apply(Ext_.util, {
	// 检测用户名的输入是否合法
	checkUsername : function(user) {
		var errorUsername = "";
		var username = user;
		var lang = Ext_.util.getCookie("lngtms.lang") || "zh_CN";

		if (username == "" || username == null) {
			errorUsername = lang == "zh_CN" ? "请输入用户名" : "your id?";
			return errorUsername;
		}
		/**
		 switch (this.isUsername(username)) {
		 case 0:
		 return errorUsername;
		 case 1: {
		 errorUsername = lang == "zh_CN" ? "用户名‘" + username + "’字符长度有误" : "your id must be between 4 and 64 characters long";
		 // 合法长度为4-64个字符
		 return errorUsername;
		 }
		 case 2: {
		 errorUsername = lang == "zh_CN" ? "用户名‘" + username + "’含有非法字符" : "Chinese characters are not allowed";
		 return errorUsername;
		 }
		 }
		 */
		return errorUsername;
	},

	// 检测用户名的辅助函数
	isUsername : function(username) {
		if (!/^.{4,64}$/.test(username)) {
			return 1;
		}
		if (/^.*[\u4e00-\u9fa5].*$/.test(username)) {// 不能含有汉字
			return 2;
		}
		return 0;
	},

	// 检测密码的输入是否合法
	checkPassword : function() {
		var errorPsdStr = "";
		// 设置密码的错误的信息
		var password = $("login_passwd").value;
		return errorPsdStr;
	},
	
	logOut : function() {
		Ext_.util.deleteCookie('token');
		
		var a = location.href.split('#');
		a.pop();
		window.location = a.join('');
	}
});
// 等待提示
lngtms.Mask = (function() {
	var body= document.getElementsByTagName('body')[0],
		mask = body.appendChild(document.createElement("div")), 
		loading = body.appendChild(document.createElement("div"));
	
	mask.className = "x-mask";
	loading.className = "x-mask-msg";
	
	mask.style.display = "none";
	loading.style.display = "none";
	
	return {
		show : function(msg) {
			loading.style.display = "block";
			mask.style.display = "block";
			loading.innerHTML = '<div class="x-mask-msg-inner"><div class="x-mask-msg-text">'+lngtms.lang['login_loading'][Ext_.util.getCookie("lngtms.lang")]+'</div></div>';
			loading.style.position = 'absolute';
			loading.style['z-index'] = '101';
			loading.style.top = (mask.clientHeight/2 - loading.clientHeight/2 - 1).toString() + 'px';
			loading.style.left = (mask.clientWidth/2 - loading.clientWidth/2 - 2).toString() + 'px'; 
			
		},
		hide : function() {
			loading.style.display = "none";
			mask.style.display = "none";
		}
	};
})();

// 页头提示信息
lngtms.msgTip = (function() {
	var msgTip = document.body.appendChild(document.createElement("div"));
	msgTip.className = "msgTip";
	var isSuggestedBrowser = Ext_.isChrome || Ext_.isGecko, noCookie = navigator.cookieEnabled ? "" : '<div><b>提示:</b> 您的浏览器禁用了Cookie,系统将不能正常运行,请在浏览器中启用Cookie支持.</div><br/>', chromeSuggest = isSuggestedBrowser ? "" : '<div><b>提示: </b> 为获得最佳操作体验,我们建议您使用新版的Google Chrome浏览器或FireFox浏览器,在不低于1024*768的分辨率下浏览.' + '[ <a href="#" id="hideSuggestOnce" style="color:blue"> 隐藏 </a>/' + '<a href="#" id="hideSuggestEver" style="color:blue"> 不再提示 </a>]</div>';
	chromeSuggest = '<div><b>提示: </b> 为获得最佳操作体验,我们建议您使用新版的Google Chrome浏览器或FireFox浏览器,在不低于1024*768的分辨率下浏览.' + '[ <a href="#" id="hideSuggestOnce" style="color:blue"> 隐藏 </a>/' + '<a href="#" id="hideSuggestEver" style="color:blue"> 不再提示 </a>]</div>';
	return {
		show : function(msg) {
			// if (Ext_.util.getCookie("hideSuggestEver") || (noCookie + chromeSuggest == ""))
			// return;
			msgTip.style.display = "block";
			msgTip.innerHTML = noCookie + chromeSuggest;

			Ext_.util.addEvent($("hideSuggestOnce"), "click", function() {
				msgTip.style.display = "none";
			});
			Ext_.util.addEvent($("hideSuggestEver"), "click", function() {
				msgTip.style.display = "none";
				Ext_.util.setCookie("hideSuggestEver", "yes", (new Date()).getTime(), "/");
			});

		},
		hide : function() {
			msgTip.style.display = "none";
		}
	};
})();


/** =============Login Begin================================================================================================* */

(function() {
    
	// 多语言
	var lang = lngtms.lang = {};
	var langMenuList = {
		en : 'En',
		zh_CN : '中',
		zh_TW : '中',
		ko : 'Ko',
		ja : 'Ja'
	}, login_boxTitle = {
		en : '', //"HAWAYI",
		zh_CN : '',//"统一UI(夏威夷)",
		zh_TW : '',
		ko : '',
		ja : ''
	}, login_userTitle = {
		en : "Username",
		zh_CN : "用户名",
		zh_TW : '',
		ko : '',
		ja : ''
	}, login_passTitle = {
		en : "Password",
		zh_CN : "密码",
		zh_TW : '',
		ko : '',
		ja : ''
	}, login_missedPwd = {
		en : "Forgot your password?",
		zh_CN : "忘记密码？",
		zh_TW : '',
		ko : '',
		ja : ''
	}, login_button = {
		en : "Login",
		zh_CN : "登录",
		zh_TW : '',
		ko : '',
		ja : ''
	}, login_loading = lang['login_loading'] = {
		en : "loading...",
		zh_CN : "加载中...",
		zh_TW : '',
		ko : '',
		ja : ''
	},
	/*documentTitle = {
	 zh_CN : "山石网科 - 创新的网络安全厂商-保障业务稳健",
	 en : "HILLSTONE NETWORKS"
	 },*/
	noCookie = {
		zh_CN : "<div><b>提示:</b> 您的浏览器禁用了Cookie,系统将不能正常运行,请在浏览器中启用Cookie支持.</div><br/>",
		en : "<div><b>Attention:</b> Your browser has disabled cookie, system shall not work properly without it. Please enable cookie in your browser settings.</div><br/>"
	}, loginErrorMsg = {
		en : {
			loginError_1001 : 'Login timed out! Please log in again!',
			loginError_1002 : 'Login token is invalid! Please log in again!',
			loginError_1003 : 'Please login!',
			loginError_1004 : 'User name or password is incorrect!',
			loginError_1005 : 'Network Anomaly!',
            loginError_1006 : 'Client certificate common name is different from username',
            loginError_1007 : 'http protocol validate'
		},
		zh_CN : {
			loginError_1001 : '登录已超时！请重新登录！',
			loginError_1002 : '登录令牌无效！请重新登录！',
			loginError_1003 : '请先进行登录！',
			loginError_1004 : '用户名或密码错误！',
			loginError_1005 : '网络异常！',
            loginError_1006 : '用户名与客户端证书用户名(cn)不一致',
            loginError_1007 : 'http协议冲突'
		},
		zh_TW : {
			loginError_1001 : '登錄已超時！請重新登錄！',
			loginError_1002 : '登錄令牌無效！請重新登錄！',
			loginError_1003 : '請先進行登錄！',
			loginError_1004 : '用戶名或密碼錯誤！',
			loginError_1005 : '網絡異常！',
            loginError_1006 : 'Client auth failed',
            loginError_1007 : 'http protocol validate'
		},
		ko : {
			loginError_1001 : '로그인 시간이 초과되었습니다! 다시 로그인 해주세요!',
			loginError_1002 : '로그인 토큰이 유효하지 않습니다! 다시 로그인 해주세요!',
			loginError_1003 : '로그인 해주세요!',
			loginError_1004 : '사용자 이름이나 암호가 잘못되었습니다!',
			loginError_1005 : '네트워크 변형!',
            loginError_1006 : 'Client auth failed',
            loginError_1007 : 'http protocol validate'
		},
		ja : {
			loginError_1001 : 'ログインがタイムアウトしました！もう一度ログインしてください！',
			loginError_1002 : 'ログイントークンが無効です！もう一度ログインしてください！',
			loginError_1003 : 'ログインしてください！',
			loginError_1004 : 'ユーザー名またはパスワードが間違っています！',
			loginError_1005 : 'ネットワーク異常！',
            loginError_1006 : 'Client auth failed',
            loginError_1007 : 'http protocol validate'
		}
	};

	/**
	 * 登录状态标志 防止重复发送登录请求
	 */
	var isLoggingin = false;
	
	/**
	 *加载语言菜单
	 */
	loadLangMenu();

	// 根据用户系统默认语言设置设置语言
	setLanguage(Ext_.util.getCookie("lngtms.lang") || '');

	/**
	 * 验证cookie, 如服务器cookie验证成功则加载所需类库, 否则初始化登录界面
	 */
	if (Ext_.util.getCookie("token")) {

		if (GLOBAL_CONFIG.USERVERIFY) {
			//TODO 验证 token 是否有效
			Ext_.Ajax.request({
//				url : 'rest/login',
				url : 'data/login.json',
				async : false,
				method : 'GET',
				success : function(response) {

					Ext_.apply(GLOBAL_CONFIG, {
						USERNAME : Ext_.util.getCookie('username'),
						HTTP_PROTOCOL : Ext_.util.getCookie('httpProtocol')
					});
					
					isLoggingin = false;
					var responseObj = Ext_.util.decode(response.responseText);

					if (responseObj.success) {
						//token 有效
						tokenValid();
					} else {
						//初始化登录页面
						initLogin();

						//1.登录已超时, 2.登录令牌无效, 3.请先进行登录
						var errorCode = responseObj.exception.code;
						showErrorMsg(errorCode);
					}
				},
				failure : function(response) {
					//网络异常
					var responseObj = Ext_.util.decode(response.responseText);
					if (responseObj.code)
						showErrorMsg(responseObj.code);
					else
						showErrorMsg('loginError_1005');
				},
				headers : {
					'token' : Ext_.util.getCookie("token")
				},
				params : {}
			});
		} else {
			tokenValid();
		}
	} else {
		//初始化登录页面
		initLogin();
	}

	/**
	 * 初始化登录界面
	 */
	function initLogin() {
		//debugger;
		// 显示登录界面
		document.getElementById("container").style.display = "block";

		// 绑定事件
		Ext_.util.addEvent($("login_username"), "keydown", function(e) {
			if ((e.which || e.keyCode) == 13 && $("login_username").value != "") {
				$("login_passwd").focus();
			}
		});
		Ext_.util.addEvent($("login_passwd"), "keydown", function(e) {
			if ((e.which || e.keyCode) == 13) {// to be modified
				if (isLoggingin)
					return;
				login();
			}
		});
		/** bind events for inputs & input options **/
		var ctrlCrossState = function (e) {
			var cross = Ext_.isIE ? e.srcElement.parentElement.children[1] : e.target.parentElement.children[1];
			if ((e.target || e.srcElement).value != "") {
				cross.style.display = 'block';
			} else {
				cross.style.display = 'none';
			}
		}
		Ext_.util.addEvent($("login_username"), "keyup", ctrlCrossState);
		Ext_.util.addEvent($("login_passwd"), "keyup", ctrlCrossState);
		
		Ext_.util.addEvent($("login_username"), "focus", ctrlCrossState);
		Ext_.util.addEvent($("login_passwd"), "focus", ctrlCrossState);
		
		Ext_.util.addEvent($("login_username"), "blur", function (e) {
			var cross = Ext_.isIE ? e.srcElement.parentElement.children[1] : e.target.parentElement.children[1];
			if (e.relatedTarget) {
				cross.style.display = 'none';
			} else {
				(function () {
					cross.style.display = 'none';
				}).defer(150);	
			}
				
			
		});
		Ext_.util.addEvent($("login_passwd"), "blur", function (e) {
			var cross = Ext_.isIE ? e.srcElement.parentElement.children[1] : e.target.parentElement.children[1];
			if (!Ext_.isIE && e.relatedTarget) {
				cross.style.display = 'none';
			} else {
				(function () {
					cross.style.display = 'none';
				}).defer(150);	
			}
		});
		
		Ext_.util.addEvent($("login_username").parentElement.children[1], "click", function (e) {
			$("login_username").value = '';
			e.target.style.display = 'none';
		});
		Ext_.util.addEvent($("login_passwd").parentElement.children[1], "click", function (e) {
			$("login_passwd").value = '';
			e.target.style.display = 'none';
		});

		$("login_username").focus();
		
		/** bind events for inputs & input options ends**/
		
		//lang menu 绑定事件
		for (var i = 0; i < GLOBAL_CONFIG.LANGUAGES.length; i++) {
			var langItem = GLOBAL_CONFIG.LANGUAGES[i];
			if (document.getElementById(langItem)) {

				Ext_.util.addEvent($(langItem), "click", function(e) {
					var el = e.target || e.srcElement;
					//debugger;
					setLanguage(el.id);
					el.className = 'boxBannerLang active';
					
					for (var i = 0; i < el.parentElement.childNodes.length; i++) {
						var tmp = el.parentElement.childNodes[i];
						if (tmp != el) {
							tmp.className = 'boxBannerLang';
						}
					}
				});
			}
		}

		Ext_.util.addEvent($("login_button"), "click", function() {
			if (isLoggingin)
				return;
			login();
		});
	}

	
    
    /**
	 * 登录
	 */
	function login() {
        isLoggingin = true;
		setButtonState("down");
        //检查和登录相关的cookie是否完整
		// 登录验证
		var errorMsg = Ext_.util.checkUsername($("login_username").value);
		if (errorMsg != "") {
			//alert(errorMsg);
			isLoggingin = false;
			setButtonState("up");
			$("login_username").focus();
			return;
		}

		if (GLOBAL_CONFIG.USERVERIFY) {
			//获取if_vsys_id和vr_id
            var if_vsys_id = '0';
            var vr_id = '0';
            
            if (GLOBAL_CONFIG.DEBUGINFO.remoteServer == '127.0.0.1') {
                Ext_.Ajax.request({
                    url : 'login/get-resource',
                    async : false,
                    method : 'GET',
                    success : function(response) {
                        var sourceArray = response.responseText.split(',');
                        for (var i = 0; i < sourceArray.length; i++) {
                            var sourceItem = sourceArray[i];
                            var sourceItemArray = sourceItem.split(':');
                            if (sourceItemArray[0] == 'vsysid') {
                                if_vsys_id = sourceItemArray[1];
                            }   
                            else if (sourceItemArray[0] == 'vrid') {
                                vr_id = sourceItemArray[1];
                            }
                        }
                    }
                });
            }
            
            //debugger;
			//提交用户名密码
			Ext_.Ajax.request({
//				url : 'rest/login',
				url : 'data/login.json',
				method : 'POST',
				success : function(response) {
					isLoggingin = false;
					var responseObj = Ext_.util.decode(response.responseText);

					if (responseObj.success) {
						Ext_.util.setCookie('token', encodeURI(responseObj.result.token));
						Ext_.util.setCookie('platform', responseObj.result.platform);
                        Ext_.util.setCookie('hw_platform', responseObj.result.hw_platform);
                        Ext_.util.setCookie('company', responseObj.result.company);
                        Ext_.util.setCookie('oemid', responseObj.result.oemId);
						Ext_.util.setCookie('vsysid', responseObj.result.vsysId);
                        Ext_.util.setCookie('vsysName', responseObj.result.vsysName);
                        Ext_.util.setCookie('role', responseObj.result.role);
                        Ext_.util.setCookie('license', responseObj.result.license);
                        Ext_.util.setCookie('httpProtocol', responseObj.result.httpProtocol);

                        // Ext_.util.setCookie('overseaLicense', responseObj.result.overseaLicense);
						
                        var userName = $("login_username").value;
                        if (userName.indexOf('\\') > -1) {
                            userName = userName.split('\\')[1];
                        }
                        Ext_.util.setCookie('username', userName); //存入用户名
						//token 有效
						window.location.reload();
					} else {
						//TODO 错误提示
						var errorCode = responseObj.exception.code;
						showErrorMsg(errorCode);
					}
                    
                    setButtonState("up");
				},
				failure : function(response) {
					isLoggingin = false;
					//网络异常
					var responseObj = Ext_.util.decode(response.responseText);
					if (responseObj.exception.code) {
                        showErrorMsg(responseObj.exception.code);
                    }
					else {
                        showErrorMsg('loginError_1005');
                    }
						
                    setButtonState("up");
				},
				params : {
					userName: $("login_username").value,
					password: $("login_passwd").value,
					ifVsysId: if_vsys_id,
                    vrId: vr_id,
					lang: Ext_.util.getCookie("lngtms.lang")
				}
			});
		} 
        else {
			Ext_.util.setCookie('token', 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
            Ext_.util.setCookie('username', $("login_username").value); 
            Ext_.util.setCookie('license', '{"license":["av","qos","nbc","url","ips","app"]}'); 
            Ext_.util.setCookie('role', '0'); 
            Ext_.util.setCookie('vsysid', '0');
            Ext_.util.setCookie('vsysName', 'root');
            Ext_.util.setCookie('oemid', '6');
            Ext_.util.setCookie('company', 'Hillstone Networks');
            
            Ext_.Ajax.request({
				url : 'rest/platform',
				async : false,
				method : 'GET',
				success : function(response) {
                    var returnObj = eval('(' + response.responseText + ')')
                    Ext_.util.setCookie('platform', returnObj.result.platform);
                    Ext_.util.setCookie('hw_platform', returnObj.result.hw_platform);
				},
				headers : {
					'token' : Ext_.util.getCookie("token")
				}
			});
            setButtonState("up");
			//token 有效
			window.location.reload();
		}
        
	}

	/**
	 * 设置登录按钮的按下状态
	 *
	 * @param state :
	 *            "up"/"down"
	 */
	function setButtonState(state) {
		if (state == "down") {
			// $("login_button").style.backgroundPosition = "0px -44px";
			$("login_button").className = 'boxButtonDisabled';
			$("login_button").textContent = login_button[lan.toString()] + '...';
			$("login_button").blur();
		}	
		
		if (state == "up") {
			// $("login_button").style.backgroundPosition = "0px -0px";
			$("login_button").className = 'boxButton';
			$("login_button").textContent = login_button[lan.toString()];
		}
	}

	/**
	 * 加载 语言菜单
	 */
	function loadLangMenu() {
		var langs = GLOBAL_CONFIG.LANGUAGES;
		var langMenuEl = document.getElementById('langMenu');
		var iLangMenu = [];
		for (var i = 0; i < langs.length; i++) {
			var langItem = langs[i];
			var menuItemStr = '<a id=' + langItem + ' href="javascript:;" class="boxBannerLang'+ (Ext_.util.getCookie("lngtms.lang") == langItem ? ' active' : '') +'">' + langMenuList[langItem] + '</a>';
			iLangMenu.push(menuItemStr);
			if (i < langs.length - 1)
				iLangMenu.push('<span class="boxBannerLang"> | </span>');
		}
		langMenuEl.innerHTML = iLangMenu.join('');
	}

	/**
	 * 设置登录界面语言
	 */
	function setLanguage(lang) {

		// 获取用户系统默认语言设置
		var sysLang = (function() {
			var localLan = navigator.language || navigator.systemLanguage;
			localLan = localLan.replace('-', '_');
			return GLOBAL_CONFIG.LANGUAGES['localLan'] ? GLOBAL_CONFIG.LANGUAGES['localLan'] : GLOBAL_CONFIG.LANGUAGES[0];
		})();

		// 默认语言
		lan = lang || sysLang;

		$("login_boxTitle").innerHTML = login_boxTitle[lan.toString()];
		$("login_userTitle").innerHTML = login_userTitle[lan.toString()];
		$("login_passTitle").innerHTML = login_passTitle[lan.toString()];
		// $("login_missedPwd").innerHTML = login_missedPwd[lan.toString()];
		$("login_button").innerHTML = login_button[lan.toString()];

	}

	/**
	 * 验证有效
	 */
	function tokenValid() {
		//token 有效
		document.getElementById("container").style.display = 'none';
		// loadLanguage();
		loadLibrary('');
		lngtms.Mask.show();
		lngtms.msgTip.hide();
	}

	/**
	 * 错误信息展示
	 */
	function showErrorMsg(errorCode) {

		var lan = Ext_.util.getCookie("lngtms.lang");
		var msg = loginErrorMsg[lan];
		if (errorCode) {
			var msgLabel = document.getElementById('errorMsgLabel');
			msgLabel.innerHTML = msg ? msg[errorCode] : '';

			//淡出效果
			msgLabel.time ? clearInterval(msgLabel.time) : '';
			msgLabel.style.opacity = 1;
			msgLabel.style.filter = 'alpha(opacity=100)';
			msgLabel.iAlpha = 100;
			msgLabel.time ? clearInterval(msgLabel.time) : '';
			msgLabel.time = setInterval(function() {
				domoveEffect(msgLabel);
			}, 120);
		}
	}

	/**
	 * 移除淡出效果
	 */
	function domoveEffect(obj) {
		var iSpeed = 5;
		if (obj.iAlpha <= iSpeed) {
			clearInterval(obj.time);
			obj.iAlpha = 0;
			obj.time = null;
		} else {
			obj.iAlpha -= iSpeed;
		}
		obj.style.opacity = obj.iAlpha / 100;
		obj.style.filter = 'alpha(opacity=' + obj.iAlpha + ')';
	}

	/**
	 * 加载js库文件
	 */
	function loadLibrary(debug) {
		
		debug == 'debug' ? 
			document.write(document.getElementById('head_debug').innerHTML.match(/\<script[^\<]*\<\/script\>|\<link[^\>]*\>/g).join('')) : 
			document.write(document.getElementsByTagName('head')[0].innerHTML.match(/\<script[^\<]*\<\/script\>|\<link[^\>]*\>/g).join(''));

		// load language
		// document.write(
		// '<script src="locale/lngtms-lang-'+ navigator.language.replace('-', '_') +'.js"></script>'
		// );
		
		// var rs = document.getElementsByTagName('head')[0].innerHTML.match(/\<script[^\<]*\<\/script\>|\<link[^\>]*\>/g);
		// for (var i = 0; i < rs.length; i++) {
			 // document.getElementsByTagName('head')[0].appendChild(Ext.DomHelper.createContextualFragment(rs[i]).firstChild);
		// }

	}

	function loadLanguage() {

		document.write('locale/');

	}

	/**
	 * 是否取消分辨率提示
	 */
	function hasHint() {
		var clientHeight = parseInt(document.documentElement.clientHeight);
		var clientWidth = parseInt(document.documentElement.clientWidth);
		if (clientHeight < 600 && clientWidth < 1024) {
			//alert('H:'+clientHeight + ' W:' +clientWidth)
			// 显示提示标签
			lngtms.msgTip.show();
		} else {
			lngtms.msgTip.hide();
		}
	}

	/**
	 * 调整 Login 页面布局
	 */
	function adjustLayout() {
		hasHint();

		var minHeight = 600, maxHeight = 951, header = 48, footer = 30, mainContentMinHeight = 500, scrollThick = 20;

		var clientHeight = parseInt(document.documentElement.clientHeight);

		var mainContentHeight = clientHeight - header - footer;

		//console.log('clientHeight : '+clientHeight );
		var mainContent = document.getElementById("mainContent");
		//debugger;
		if (clientHeight > minHeight && clientHeight < maxHeight) {
			mainContent.style.height = mainContentHeight + "px";
			mainContent.style.overflow = 'hidden';
			document.getElementsByTagName('body')[0].style.overflow = 'hidden';
			//禁止鼠标滚轮事件
			// if(document.addEventListener){
				// document.addEventListener('DOMMouseScroll', function(){return false;}, false);
			// }
			// window.onmousewheel = document.onmousewheel = function(){return false;};//IE/Opera/Chrome/Safari

		} else {
			mainContent.style.height = (mainContentMinHeight + scrollThick) + "px";
			mainContent.style.overflow = 'hidden';
			document.getElementsByTagName('body')[0].style.overflow = 'auto';
			
			//禁止鼠标滚轮事件

			// if(document.addEventListener){
				// document.addEventListener('DOMMouseScroll', function(){return true;}, false);
			// }
			// window.onmousewheel = document.onmousewheel = function(){return true;};//IE/Opera/Chrome/Safari

		}
	}

	// adjustLayout();

	// window.onload = adjustLayout;
	// window.onresize = adjustLayout;
	
	// adjust height of mainContent
	
	$('mainContent').setAttribute('style', 'height:'+((window.innerHeight || window.screen.height) - $('footer').clientHeight) +'px');

})();
